package zuoye_3_24;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

//拷贝一个文件夹，包含子文件夹
public class Zuoye3 {
    public static void main(String[] args) {
        String sourceDirectoryPath = "E:\\zhuo_main_fang_zhi\\aaa";
        String destinationDirectoryPath = "E:\\zhuo_main_fang_zhi\\bbb";

        File sourceDirectory = new File(sourceDirectoryPath);
        File destinationDirectory = new File(destinationDirectoryPath);

        copyDirectory(sourceDirectory, destinationDirectory);
    }

    public static void copyDirectory(File source, File destination) {
        if (!destination.exists()) {
            destination.mkdir();
        }

        if (source.isDirectory()) {
            String files[] = source.list();
            for (String file : files) {
                File srcFile = new File(source, file);
                File destFile = new File(destination, file);

                copyDirectory(srcFile, destFile);
            }
        } else {
            try {
                Files.copy(source.toPath(), destination.toPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}